<html>
<head><meta charset="utf-8"><title>Closures vs. function names type inference · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Closures.20vs.2E.20function.20names.20type.20inference.html">Closures vs. function names type inference</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="199314514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Closures%20vs.%20function%20names%20type%20inference/near/199314514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Closures.20vs.2E.20function.20names.20type.20inference.html#199314514">(May 31 2020 at 17:46)</a>:</h4>
<p>The type of <code>x</code> is correctly resolved as <code>Option&lt;Option&lt;i32&gt;&gt;</code>:</p>
<div class="codehilite"><pre><span></span><code>let x = iter::repeat(5).map(|i| Some(i)).next();
</code></pre></div>


<p>Whereas here, it can't be resolved:</p>
<div class="codehilite"><pre><span></span><code>let x = iter::repeat(5).map(Some).next();
</code></pre></div>



<a name="199314524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Closures%20vs.%20function%20names%20type%20inference/near/199314524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Closures.20vs.2E.20function.20names.20type.20inference.html#199314524">(May 31 2020 at 17:46)</a>:</h4>
<p>I'm not sure whether this is a known issue. I'm having trouble finding it in the GitHub issues.</p>



<a name="199314550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Closures%20vs.%20function%20names%20type%20inference/near/199314550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Closures.20vs.2E.20function.20names.20type.20inference.html#199314550">(May 31 2020 at 17:47)</a>:</h4>
<p>(Nothing special about enum constructors here; the same behavior holds with normal functions)</p>



<a name="199314552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Closures%20vs.%20function%20names%20type%20inference/near/199314552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Closures.20vs.2E.20function.20names.20type.20inference.html#199314552">(May 31 2020 at 17:47)</a>:</h4>
<p>I think that would be <a href="https://github.com/rust-analyzer/rust-analyzer/issues/4281">https://github.com/rust-analyzer/rust-analyzer/issues/4281</a></p>



<a name="199314615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Closures%20vs.%20function%20names%20type%20inference/near/199314615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Closures.20vs.2E.20function.20names.20type.20inference.html#199314615">(May 31 2020 at 17:49)</a>:</h4>
<p>This is particularly bad for our codebase since we have a style guideline not to introduce unnecessary closures in cases like this. <span class="user-mention" data-user-id="133169">@matklad</span> is this an easy fix that you could give me pointers to? I can try to do it if so.</p>



<a name="199314698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Closures%20vs.%20function%20names%20type%20inference/near/199314698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Closures.20vs.2E.20function.20names.20type.20inference.html#199314698">(May 31 2020 at 17:51)</a>:</h4>
<p>I don't think this has an easy fix, it needs some groundwork on the chalk's side (see the linked chalk issues in the issue)</p>



<a name="199314747"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Closures%20vs.%20function%20names%20type%20inference/near/199314747" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brennan Vincent <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Closures.20vs.2E.20function.20names.20type.20inference.html#199314747">(May 31 2020 at 17:52)</a>:</h4>
<p>Ok, thanks for letting me know.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>